# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/1 10:41
# @Author   : yangshuaishuai
# @Site     : http://www.hzdledu.cn/
# @File     : w2s1_元素的基本操作.py
# @Software : PyCharm

from selenium import webdriver
import time
#元素的基本操作
def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    #模拟键盘输入
    driver.find_element_by_id('kw').send_keys('双11特价')
    time.sleep(1)

    #模拟鼠标左键单击
    driver.find_element_by_id('su').click()
    time.sleep(3)

    #获取元素text
    text=driver.find_element_by_xpath('//*[@id="3001"]/div/div[1]/div/div/h3/div/a')
    print(text)
    #获取元素属性
    #get_attribute():适合于所标签
    att=driver.find_element_by_xpath('//*[@id="3001"]/div/div[1]/div/div/h3/div/a').get_attribute('href')
    print(att)
    #清空输入框
    #clear():只针对<input>,建议在每次输入前先clear
    driver.find_element_by_id('kw').clear()
    driver.find_element_by_id('kw').send_keys('双12特价')
    time.sleep(1)

    driver.quit()





if __name__=='__main__':
    foo1()